<?php

class Rcp_Methods_Request_CancelCalendarEvent {
	
	/**
	 *
	 * @var Rcp_Methods_Data_App
	 */
	public $app;
	public $userId;
	public $range;
	
	public function __construct($params) {
		$this->app = new Rcp_Methods_Data_App($params->app);
		$this->range = new Rcp_Methods_Data_DateRange($params->range);
	}
	
	public function process() {
		$calendarEvents = RcpCalendarEventsQuery::create()
		->filterByActive(true)
		->filterByUserId($this->userId)
		->filterByDate($this->range->from->format('Y-m-d'), Criteria::GREATER_EQUAL)
		->filterByDate($this->range->to->format('Y-m-d'), Criteria::LESS_EQUAL)
		->find();
		
		$response = new Rcp_Methods_Response_GetCalendarEvents();
		
		foreach ($calendarEvents as $event) {
			if (!($event instanceof RcpCalendarEvents))
				continue;
			$this->setNullTime($calendarEvents, $event);				
			$response->calendarEvents[] = new Rcp_Methods_Data_CalendarEvent($event);
		}
		
		return $response;
	}
	
}